package com.ywj.interview.thread.stopThread;

public class NormalThreadInterrupt extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            System.out.println("i=" + i);
        }
    }

//    @Override
//    public void run() {
//        for (int i = 0; i < 10000; i++) {
//            //使用 Thread.isInterrupted() 来判断当前线程是否被中断。若线程被中断，退出for循环、结束线程
//            if (Thread.currentThread().isInterrupted()) {
//                //处理中断
//                break;
//            }
//            System.out.println("i=" + i);
//        }
//    }

    public static void main(String[] args) throws InterruptedException {
        NormalThreadInterrupt t1 = new NormalThreadInterrupt();
        t1.start();
        Thread.sleep(30);
        t1.interrupt();
    }
}
